package LeetCode;

import java.util.Arrays;

public class RotateArray {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        fun1(arr,10000);
        System.out.println(Arrays.toString(arr));
    }
    public static void fun(int[] arr, int k) {
        k %= arr.length;
        rotate(arr,0,arr.length - 1);
        rotate(arr,0,k-1);
        rotate(arr,k, arr.length-1);
    }
    public static void rotate(int[] arr,int left, int right) {
        while (left < right) {
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
            left++;
            right--;
        }
    }

    public static void fun1(int[] nums,int k) {
        if(nums.length == 1 || nums.length == 0) {
            return;
        }
        k %= nums.length;
        int[] temp = new int[k];
        System.arraycopy(nums,nums.length - k, temp, 0,k);
        System.arraycopy(nums,0,nums,k,nums.length - k);
        for(int i = 0;i < temp.length ; i++) {
            nums[i] = temp[i];
        }
    }

}
